public class test {
}
class Solution {
    public int maxSubArray(int[] nums) {
        int ans = Integer.MIN_VALUE;
        int count = 0;
        for(int i=0; i<nums.length; i++){
            count += nums[i];
            if(count > ans) ans = count;
            if(count < 0) count = 0;
        }
        return ans;
    }
}